package com.fingard.dsp.bank.directbank.bjums01;

import com.alibaba.fastjson.JSONObject;
import com.fingard.dsp.bank.directConfig.ActSetItem;
import com.fingard.dsp.bank.reqrespobj.unifiedorder.ReqQueryOrder;
import com.fingard.dsp.bank.reqrespobj.unifiedorder.RetAtsQueryOrder;

import java.util.Map;

public class BJUMS01UnifiedOrder extends BJUMS01Base {
    public RetAtsQueryOrder queryUnifiedOrder(ReqQueryOrder p_req) {
        RetAtsQueryOrder retAts = new RetAtsQueryOrder();
        retAts.rdSeq = p_req.rdSeq;
        try {
            ActSetItem actItem = this.getBankConfig().getActSetItem(p_req.ownAct, "");
            if (actItem != null) {
                Map<String, Object> param = getParam(actItem);
                param.put("tranno",  BJUMS01TransType.QR002001);
                param.put("reqOrderNo",  p_req.rdSeq);
                param.put("orderNo",  "");
                param.put("merchId",  actItem.merchantId);
                String sign = addSign(null, param, actItem.saltKey);
                WriteBankLogLn("签名结果:"+sign);
                param.put("signature", sign);
                JSONObject jsonObj=new JSONObject(param);
                String[] tmpStrRet = sendToBank(jsonObj.toJSONString(),bankFront.serverURL);
                if(tmpStrRet[0].length() == 0){
                    JSONObject resultObj = JSONObject.parseObject(tmpStrRet[1]);
                    String  pay_result = resultObj.getString("respCode");
                    String resp_msg = resultObj.getString("respMsg");
                    String paySt = resultObj.getString("paySt");
                    retAts.respCode = "0";
                    retAts.respInfo = resp_msg;
                    retAts.outTransID  = p_req.outTransID;
                    if("000007".equals(pay_result)){
                        retAts.transState = pay_result;
                    }else{
                        retAts.transState = paySt;
                    }
                    retAts.payInfoCode = pay_result;
                }else {
                    retAts.respCode = "-1";
                    retAts.respInfo = tmpStrRet[1];
                }
            } else {
                retAts.respCode = "-1";
                retAts.respInfo = "未找到账号[" + p_req.ownAct + "]商户配置信息!";
            }
        } catch (Exception ex) {
            ex.printStackTrace();
            retAts.respCode = "-1";
            retAts.respInfo = ex.getMessage();
            WriteBankLogLn(ex);
        }
        return retAts;
    }
}
